﻿<?xml version="1.0" encoding="utf-8" ?>

<cls:class
	name="AhciCdDriveBlockIterator"
	type="http://metalx.org/Storage/Ahci/AhciCdDriveBlockIterator"
	xmlns="http://metalx.org/Program"
	xmlns:pata="http://metalx.org/Pc/Pata/Ports"
	xmlns:status="http://metalx.org/Pc/Pata/Status"
	xmlns:drive="http://metalx.org/Pc/Pata/DriveSelect"
	xmlns:cmd="http://metalx.org/Pc/Pata/Commands"
	xmlns:port="http://metalx.org/Pc/Ports"
	xmlns:dbg="http://metalx.org/i386/Functions/Debug"
	xmlns:lst="http://metalx.org/i386/Functions/List"
	xmlns:con="http://metalx.org/i386/Functions/Console"
	xmlns:int="http://metalx.org/i386/Functions/Integer"
	xmlns:str="http://metalx.org/i386/Functions/String"
	xmlns:clsf="http://metalx.org/i386/Functions/Class"
	xmlns:mm="http://metalx.org/i386/Functions/MemoryManager"
	xmlns:var="http://metalx.org/Variable"
	xmlns:sys="http://metalx.org/i386/Functions/System"
	xmlns:cat="http://metalx.org/i386/Functions/Catalog"
	xmlns:obj="http://metalx.org/i386/Functions/Object"
	xmlns:cd="http://metalx.org/i386/Functions/CdDrive"
	xmlns:asc="http://metalx.org/Ansi/Ascii"
	xmlns:ari="http://metalx.org/Intel/80386/Arithmetic"
	xmlns:logic="http://metalx.org/Intel/80386/Logic"
	xmlns:math="http://metalx.org/Intel/80386/Math"
	xmlns:imm="http://metalx.org/Intel/80386/Immediate"
	xmlns:inc="http://metalx.org/Intel/80386/Increment"
	xmlns:cpu="http://metalx.org/Intel/80386/Operators"
	xmlns:op="http://metalx.org/Intel/80386/Operands"
	xmlns:shift="http://metalx.org/Intel/80386/Shift"
	xmlns:cls="http://metalx.org/Class">

	<cls:field name="Block" type="http://metalx.org/Integer" offset="0"/>
	<cls:field name="Device" type="http://metalx.org/Pci/PciDevice" offset="4"/>
	<cls:field name="Port" type="http://metalx.org/Byte" offset="8"/>

	<cls:method name="Next" type="http://metalx.org/Ahci/AhciCdDriveBlockIterator">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:IncrementFunction/>
		<inc:IncrementSIAddress/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="Previous" type="http://metalx.org/Ahci/AhciCdDriveBlockIterator">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:IncrementFunction/>
		<inc:DecrementSIAddress/>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="Skip" type="http://metalx.org/Ahci/AhciCdDriveBlockIterator">
		<cpu:ExchangeOperandWithRegister/>
		<op:BP-SPRegister/>

		<cpu:PullSIFromStack/>

		<cpu:ExchangeOperandWithRegister/>
		<op:BP-SPRegister/>

		<obj:GetData/>

		<cpu:CopySIAddressToAXAndIncrementSI/>

		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:AddRegisterToOperand/>
		<op:AX-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<cpu:ReturnToNearCaller/>
	</cls:method>

	<cls:method name="ToString" type="http://metalx.org/String">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetData/>

		<cpu:LogicFunction/>
		<logic:PushSIAddress/>

		<cpu:CopyOperandToRegister/>
		<op:DX-SIAddressPlusImmediate8/>
		<byte>4</byte>

		<!--Select Drive-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:DriveAndHead/>

		<cpu:CopyOperandToRegister8/>
		<op:AL-SIAddressPlusImmediate8/>
		<byte>8</byte>

		<cpu:ShiftRegisterByImmediateFunction8/>
		<shift:ShiftALRegisterLeft/>
		<byte>4</byte>

		<cpu:OrALWithImmediate/>
		<binary>11100000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:DriveAndHead/>

		<!--Wait For Drive Select-->
		<cpu:CallRelative/>
		<addressOf ref="sleep" type="Relative32"/>

		<!--Disable DMA-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Features/>

		<cpu:CopyImmediateToAL/>
		<binary>00000000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Features/>

		<!--Enable IRQs-->
		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:AddToDXRegister/>
		<hex>0206</hex>

		<cpu:CopyImmediateToAL/>
		<binary>00000000</binary>

		<cpu:WriteALToDXPort/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<hex>0206</hex>

		<!--Set Byte Count 0-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:ByteCount0/>

		<cpu:CopyImmediateToAL/>
		<hex>00</hex>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:ByteCount0/>

		<!--Set Byte Count 1-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:ByteCount1/>

		<cpu:CopyImmediateToAL/>
		<hex>08</hex>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:ByteCount1/>

		<!--Send ATAPI Packet Command-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Command/>

		<cpu:CopyImmediateToAL/>
		<cmd:Packet/>

		<cpu:WriteALToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Command/>

		<!--Wait While Busy-->
		<cpu:CallRelative/>
		<addressOf ref="wait" type="Relative32"/>

		<!--<cpu:CallRelative/>
		<addressOf ref="poll" type="Relative32"/>-->

		<!--Send ATAPI Packet-->
		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Data/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0028</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:PullAXFromStack/>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:RollAXRegisterRight/>
		<byte>16</byte>

		<cpu:Operand16/>
		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:RollAXRegisterRight/>
		<byte>8</byte>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:RollAXRegisterLeft/>
		<byte>16</byte>

		<cpu:Operand16/>
		<cpu:ShiftRegisterByImmediate8Function/>
		<shift:RollAXRegisterRight/>
		<byte>8</byte>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0001</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:Operand16/>
		<cpu:CopyImmediateToAX/>
		<hex>0000</hex>

		<cpu:Operand16/>
		<cpu:WriteAXToDXPort/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Data/>

		<!--Wait While Busy-->
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>
		<cpu:WaitForInterrupt/>

		<!--Get Byte Count 0-->
		<!--<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:ByteCount0/>
		
		<cpu:ReadFromDXPortToAL/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:ByteCount0/>-->

		<!--Get Byte Count 1-->
		<!--<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:ByteCount1/>

		<cpu:ReadFromDXPortToAL/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:ByteCount1/>-->

		<!--<cpu:CallRelative/>
		<addressOf ref="sleep" type="Relative32"/>

		<cpu:CallRelative/>
		<addressOf ref="wait" type="Relative32"/>-->

		<!--Read Data-->
		<!--<cpu:CallRelative/>
		<addressOf ref="poll" type="Relative32"/>-->

		<mm:CheckOut length="2052"/>

		<cpu:PushDIToStack/>

		<cpu:CopyImmediateToAX/>
		<int>2048</int>

		<cpu:CopyAXToDIAddressAndIncrementDI/>

		<cpu:CopyImmediateToCX/>
		<int>1024</int>

		<cpu:Operand16/>
		<cpu:Repeat/>
		<cpu:ReadFromDXPortToDIAddressAndIncrementDI/>

		<cpu:PullDIFromStack/>

		<str:CreateObject/>

		<cpu:ReturnToNearCaller/>

		<label id="sleep"/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:AddToDXRegister/>
		<hex>0206</hex>

		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>
		<cpu:ReadFromDXPortToAL/>

		<cpu:Operand16/>
		<cpu:MathImmediateToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<hex>0206</hex>

		<cpu:ReturnToNearCaller/>

		<label id="wait"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Status/>

		<label id="whileBusy"/>

		<cpu:ReadFromDXPortToAL/>

		<cpu:AndALWithImmediate/>
		<status:Busy/>

		<cpu:BranchToRelative8IfNotZero/>
		<addressOf ref="whileBusy" type="Relative8"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Status/>

		<cpu:ReturnToNearCaller/>

		<label id="poll"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:AddToDXRegister/>
		<pata:Status/>

		<label id="whileEmpty"/>

		<cpu:ReadFromDXPortToAL/>

		<cpu:AndALWithImmediate/>
		<status:DataRequest/>

		<cpu:BranchToRelative8IfZero/>
		<addressOf ref="whileEmpty" type="Relative8"/>

		<cpu:MathImmediate8ToOperandFunction/>
		<math:SubtractFromDXRegister/>
		<pata:Status/>
	</cls:method>

	<cls:method name="GetClass" type="http://metalx.org/Class">
		<cpu:CopyRegisterToOperand/>
		<op:DI-SIRegister/>

		<obj:GetType/>

		<cpu:CopyRegisterToOperand/>
		<op:SI-DIRegister/>

		<clsf:CreateObject/>

		<cpu:ReturnToNearCaller/>
	</cls:method>
</cls:class>